from rest_framework.viewsets import ModelViewSet
from aaa import models
from rest_framework import serializers
from rest_framework.response import Response
import json
from django.http import JsonResponse
from aaa.utils.pager import myPageNumberPagination

class yySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.yy1170
        fields = ['index','county','point','deviceID','deviceName','record','deal','maintenance_date','deviceStatus','belong']

class yysearchView(ModelViewSet):
    queryset = models.yy1170.objects.all()
    serializer_class = yySerializer
    authentication_classes = []

    def list(self, request, *args, **kwargs):
        print('args',request._request.GET.get('pagenum'))
        devices = self.get_queryset()
        # pg = myPageNumberPagination()
        # xx = pg.paginate_queryset(queryset=self.queryset,request=request,view=self)
        # ser = yySerializer(instance=xx,many=True)
        ser = yySerializer(instance=devices,many=True)
        ret = {}
        ret['data'] = json.dumps(ser.data)
        print('ser',len(ret['data']),ret['data'])
        ret['total'] = self.queryset.count()
        return JsonResponse(ret)